#include "tronGame.h"
#define DXMGR dxManager::getInstance()
#define TITLE_SCREEN_FILE "tron-xbla-1_640_480.bmp"
#define BACKGROUND_FILE "graphpaper.bmp"
#define WIDTH 640
#define HEIGHT 480
#define TITLE_WIDTH 640
#define TITLE_HEIGHT 480
 
tronGame::tronGame()
{
	gameStart = false;
}

tronGame::~tronGame()
{
}

bool tronGame::init(HWND hWnd)
{
	if(!DXMGR.init(hWnd))
	{
		MessageBox(NULL, "DirectX failed to initialize", "ERROR", MB_OK);
		return false;
	}

	//Grab the bitmap from the file.
	titleScreen = DXMGR.getSurfaceFromBitmap(TITLE_SCREEN_FILE);

	if(titleScreen == NULL)
	{
		//Failed to get a bitmap.
		return false;
	}

	background = DXMGR.getSurfaceFromBitmap(BACKGROUND_FILE);

	if(background == NULL)
	{
		//Failed to get a bitmap.
		return false;
	}

	//Fill out the Source Rectangle
	titleSource.left = 0;
	titleSource.top = 0;
	titleSource.right = titleSource.left + TITLE_WIDTH;
	titleSource.bottom = titleSource.top + TITLE_HEIGHT;

	//Fill out the Destination Rectangle
	titleDest.left = 0;
	titleDest.top = 0;
	titleDest.right = titleDest.left + WIDTH;
	titleDest.bottom = titleDest.top + HEIGHT;

	//Fill out the Source Rectangle
	backgrdSource.left = 0;
	backgrdSource.top = 0;
	backgrdSource.right = titleSource.left + TITLE_WIDTH;
	backgrdSource.bottom = titleSource.top + TITLE_HEIGHT;

	//Fill out the Destination Rectangle
	backgrdDest.left = 0;
	backgrdDest.top = 0;
	backgrdDest.right = titleDest.left + WIDTH;
	backgrdDest.bottom = titleDest.top + HEIGHT;

	directSound.InitDirectSound(hWnd);
	directSound.PlaySound();

	return true;
}

void tronGame::drawScene()
{
	//Drawing goes between this function...
	DXMGR.beginRender();
	if(!gameStart)
	{
		DXMGR.blitToSurface(titleScreen, &titleSource, &titleDest); //Drawing the title screen.
	}
	else
	{
		DXMGR.blitToSurface(background, &backgrdSource, &backgrdDest);
	}
	//... and this function.
	DXMGR.endRender();
}

void tronGame::updateScene()
{
}

void tronGame::cleanUp()
{
	titleScreen = NULL;
	directSound.CleanUp();
	DXMGR.shutdown();
}

void tronGame::startGame()
{
	//gameStart = true;
	gameStart = !gameStart;
}